﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Battle
{
    public class RushBossBattleOver : IBattleOver
    {
        public BattleType GetBattleType()
        {
            return BattleType.RUSH_BOSS;
        }

        bool localResult;
        bool remoteResult;

        OnBattleResult onResult;

        public RushBossBattleOver(OnBattleResult onResult)
        {
            this.onResult = onResult;
        }

        public void Excute()
        {
            localResult = BattleManager.Instance.battleViewCtrl.winCamp == BattleCamp.Attacker;
            remoteResult = false;
            AskRushFightResult();
        }

        void AskRushFightResult()
        {
            ProtoBuf.Message.CSRushFightEnd msg = new ProtoBuf.Message.CSRushFightEnd();
            msg.fightId = StaticData.curBattleData.fightId;
            msg.result = localResult ? 1 : 0;
            msg.optRecord = BattleNetOver.ParseOptRecord();

            NetAPI.SendHttp(ProtoBuf.Message.OpDefine.CSRushFightEnd, msg, (pack, b) =>
            {
                if (b)
                {
                    ProtoBuf.Message.SCRushFightEnd _msg = pack.kBody as ProtoBuf.Message.SCRushFightEnd;
                    remoteResult = _msg.result == 1;
                    StaticData.lastBattleEndMsg = _msg;
                    StaticData.isLastBattleWin = remoteResult;
                    End();
                }
            });

        }

        public void End()
        {

            if (onResult != null)
            {
                onResult(remoteResult);
            }
        }
    }
}
